#include <stdlib.h>
#include "cbtree.h"

#define BLOCKSIZE	(1 << 16)
#define CHUNKSIZE	(1 << 30)
#define MAXCHUNKNUM	(1 << 10)

//core data structures
typedef struct node {
	Slice key;

	struct node* left;
	struct node* right;

	int count;
} Node;

struct Btree {
	Node* root;
	void* chunkMmap[MAXCHUNKNUM];
	int chunks;
	int blocks;
};


//internal functions
BtreeRef newBtree() {
	return NULL;
}

int rebuild(BtreeRef tree, const char* path) {
	return 0;
}

int allocBlock(BtreeRef tree, void** blockPtr) {
	return 0;
}

int initChunkFile(BtreeRef tree, int* chunkId) {
	return 0;
}

int mapChunks(BtreeRef tree, const char* dir) {
	return 0;
}

int unmapChunks(BtreeRef tree) {
	return 0;
}

int destroyRoot(BtreeRef tree) {
	return 0;
}


//implementations of the public functions
int btreeOpen(const char* path, BtreeRef* result) {
	BtreeRef tree = newBtree();
	
	int err = rebuild(tree, path);
	if (err == 0) {
		*result = tree;
	}
	return err;
}

int btreeClose(BtreeRef tree) {
	unmapChunks(tree);
	destroyRoot(tree);
}

int btreeBatchWrite(BtreeRef tree, const Record* batch) {
	return 0;
}

int btreeSync(BtreeRef tree) {
	return 0;
}

int btreeSingleOrMultiQuery(BtreeRef tree, Record* queryAndResult) {
	return 0;
}

int btreePrefixOrRangeQuery(BtreeRef tree, const Record* query, Record* result) {
	return 0;
}

int btreeStatBlocks(BtreeRef tree) {
	return 0;
}

int btreeGetBlock(BtreeRef tree, int blockno, void** blockAddr) {
	return 0;
}
